#include "dropeater.h"

DropEater::DropEater(std::function<bool(QDropEvent*)> func, QObject *parent)
    : QObject{parent}
    , m_func(func)
{
    if (parent) {
        parent->installEventFilter(this);
    }
    else
        deleteLater();
}

bool DropEater::eventFilter(QObject *watched, QEvent *event)
{
    if (event->type() == QEvent::Drop) {
        if (m_func(static_cast<QDropEvent*>(event))) {
            return true;
        }
    }
    return QObject::eventFilter(watched, event);
}
